package com.service.impl;

import com.bean.entity.SubjectInfo;
import com.bean.pojo.PageAssistant;
import com.dao.SubjectInfoMapper;
import com.service.SubjectInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class SubjectInfoServiceImpl implements SubjectInfoService {

    @Autowired
    private SubjectInfoMapper subjectInfoMapper;
    @Override
    public int save(SubjectInfo t) throws Exception {
        int insert = subjectInfoMapper.insert(t);
        if (insert==1) return 1;
        throw new Exception("科目增加失败，请重新添加！");
    }

    @Override
    public int remove(SubjectInfo t) throws Exception {
        int delete = subjectInfoMapper.delete(t);
        if (delete==1) return 1;
        throw  new Exception("科目删除失败！请重新操作!");
    }

    @Override
    public int modify(SubjectInfo t) throws Exception {
        int update = subjectInfoMapper.update(t);
        if (update==1) return 1;
        throw new Exception("科目修改失败！");
    }

    @Override
    public SubjectInfo unique(SubjectInfo t) throws Exception {
        List<SubjectInfo> select = subjectInfoMapper.select(t);
        if (select.size()!=1) throw new Exception("您要查询的科目暂未找到！");
        return select.get(0);
    }

    @Override
    public List<SubjectInfo> query(SubjectInfo t) {
        return subjectInfoMapper.select(t);
    }

    @Override
    public PageAssistant<SubjectInfo> queryByPage(Map<String, Object> map, PageAssistant<SubjectInfo> pa) {
        //查询并这只总记录数
        pa.setCount(subjectInfoMapper.selectCount(map));

        //添加分页参数
        map.put("startCode",pa.getStartCode());
        map.put("pageSize",pa.getPageSize());

        //查询并设置页面内容
        pa.setItems(subjectInfoMapper.selectByPage(map));
        return pa;
    }
}
